<!--同步考核数据 机构奖惩|人员奖惩-->
<template>
  <el-dialog
    top="5vh"
    class="bonus fix-height"
    :title="title"
    :visible.sync="visible"
    width="60%"

    :close-on-click-modal="false">
    <div class="search-form">
      <el-form ref="formRef" :model="formData" label-width="80px">
        <el-form-item label="考核周期">
          <el-select v-model="formData.obtain" placeholder="请选择考核周期" @change="periodChange">
            <el-option v-for="item in periodOptions" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <el-table
        :data="tableData"
        :height="'calc(100vh - 330px)'"
        v-loading="loading"
        border>
        <el-table-column prop="" label="序号" width="55" align="center" header-align="center">
          <template slot-scope="scope">
             <span>{{scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="type == 'ry'"
          prop="personCode"
          label="人员编号"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          v-if="type == 'ry'"
          prop="personName"
          label="人员名称"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          v-if="type == 'jg'"
          prop="deptName"
          label="机构名称"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="penaltyType"
          align="center"
          label="类型">
        </el-table-column>
        <el-table-column
          prop="bonusItemName"
          align="center"
          min-width="110"
          label="奖金项名称">
        </el-table-column>
        <el-table-column
          prop="rckhScore"
          align="center"
          min-width="90"
          label="奖惩分值">
        </el-table-column>
        <el-table-column
          prop="amount"
          align="center"
          min-width="90"
          label="奖惩金额">
        </el-table-column>
        <el-table-column
          prop="actDate"
          align="center"
          min-width="110"
          label="奖惩时间">
          <template slot-scope="scope">
            <span>{{scope.row.actDate?$moment(scope.row.actDate).format("YYYY-MM-DD"):scope.row.actDate}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="computeStatus"
          align="center"
          min-width="90"
          label="放发状态">
        </el-table-column>
        <el-table-column
          prop="enableStatus"
          align="center"
          min-width="90"
          label="启用状态">
          <template slot-scope="scope">
            <span>{{ scope.row.enableStatus == 0 ? '启用' : '停用' }}</span>
          </template>
        </el-table-column>
      </el-table>

     <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel(false)">取消</el-button>
        <el-button type="primary" @click="handleSubmit" :loading="saveLoading">确定</el-button>
     </div>
  </el-dialog>
</template>

<script>
import {saveAssementList,getPeriodDic,getDataByPeriod} from '@/api/bonus/datauserrewardpunish'
export default {
  name: "asscessForm",
  data(){
    return{
      title:'同步奖惩数据',
      visible:false,
      loading:false,
      saveLoading:false,
      type:'', //人员 ry 机构 jg
      formData:{},
      periodOptions:[],
      tableData:[]
    }
  },
  methods:{
    //获取考核数据
    init(type){
      this.type = type
      this.visible=true
      this.getPeriodDic()
    },
    getPeriodDic(){
      getPeriodDic().then(res=>{
        this.periodOptions=res.data.data
      })
    },
    handleSubmit(){
      this.saveLoading = true ;
      saveAssementList(this.tableData,this.type).then(res=>{
        if(res.data.code==0){
          this.$message.success("同步成功!")
          this.handleCancel(true)
          this.saveLoading = false ;
        }
      }).catch(err=>{
        this.saveLoading = false ;
      })
    },
    //选择考核周期
    periodChange(){
      if (!this.formData.obtain) return
      this.loading = true ;
      getDataByPeriod(this.formData.obtain.replace(/-/g,''),this.type).then(res=>{
        this.tableData=res.data.data
        this.loading = false
      }).catch(err=>{
        this.loading = false
      })
    },
    handleCancel(refresh){
      this.visible = false ;
      this.tableData = [] ;
      this.formData.obtain = '' ;
      if (refresh){
        this.$emit('refresh')
      }
      this.$refs.formRef.resetFields() ;
    }
  }
}
</script>

<style scoped>

</style>
